package org.example;

import org.example.Utils.MyProxy;
import org.example.dao.*;
import org.example.dao.Impl.ObjDaoImpl;
import org.example.pojo.Obj;
import org.example.pojo.User;
import org.example.service.ObjService;
import org.example.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class Main {
    public static void main(String[] args) {

        ApplicationContext applicationContext=
        new  ClassPathXmlApplicationContext("applicationContext.xml");

        System.out.println("set注入，构造方法注入");
        User user = applicationContext.getBean("user",User.class);
        System.out.println(user);
        System.out.println("---------------------");
        Obj obj = applicationContext.getBean("obj", Obj.class);
        System.out.println(obj);
        System.out.println("----------------");

        System.out.println();
        System.out.println("xml实现依赖注入");
        System.out.println("----------------");

        UserService userService = applicationContext.getBean("userService", UserService.class);
        userService.HelloUserService();
        System.out.println("----------------");
        System.out.println();
        System.out.println("注解实现依赖注入");
        System.out.println("----------------");

        ObjService objService = applicationContext.getBean("objService", ObjService.class);
        objService.HelloObjService();
        boolean admin = objService.login("admin", "123456s");
        System.out.println(admin);
        System.out.println("----------------");

        System.out.println();
        System.out.println("通过代理实现aop");
        System.out.println("-----------------");
        MyProxy myProxy = new MyProxy();
        ObjDaoImpl objDao = new ObjDaoImpl();
        ObjDao proxy = (ObjDao) myProxy.createProxy(objDao);
        proxy.HelloUserDao();
        System.out.println("-----------------");


        System.out.println();
        System.out.println("xml注解实现aop");
        System.out.println("-----------------------");
        UDao uDao = applicationContext.getBean("uDao", UDao.class);
//        UDaoImpl uDao = new UDaoImpl();
        uDao.select();
        System.out.println("-----------------------");
        uDao.insert();
        System.out.println("-----------------------");
        uDao.delete();
        System.out.println("-----------------------");
        uDao.update();
        System.out.println("-----------------------");

        System.out.println();
        System.out.println("三种实例化bean!!!!!!!!!!");
        Bean1 bean1 = applicationContext.getBean("bean1", Bean1.class);
        bean1.toS();
        System.out.println("-----------------------");
        Bean2 bean2 = applicationContext.getBean("bean2", Bean2.class);
        bean2.toS();
        System.out.println("-----------------------");
        Bean3 bean3 = applicationContext.getBean("bean3", Bean3.class);
        bean3.toS();


        System.out.println("sss");
    }
}